class Solution {
public:
    int divide(int dividend, int divisor) {
        // todo: corner case
        
        long long l_dividend = abs((long long)dividend);
        long long l_divisor = abs((long long)divisor);
        long long res = 0;
        while(l_dividend >= l_divisor)
        {
            long long power = 1;
            long long temp = l_divisor;
            while(temp << 1 <= l_dividend)
            {
                temp <<= 1;
                power <<= 1;
            }
            res += power;
            l_dividend -= temp;
        }
        if( (dividend>0) ^ (divisor>0))  res = -res;
        return res>INT_MAX ? INT_MAX:res;
    }
};
